/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package controller.Actions;

import dao.AccountantDAO;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Accountant;
import model.Erro;
import model.User;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author adriano.lourenco
 */
public class SearchAllAccountantAction  extends Action{

    @Override
    public ActionForward execute(ActionMapping mapping, 
            ActionForm form, 
            HttpServletRequest request, 
            HttpServletResponse response) throws Exception{
         try {
            User user = (User) request.getSession().getAttribute("User");
            if (user == null) {
                return mapping.findForward("erroAlias");
            } 
//             if (user.profile(user.getLstprofile())) {
//                request.getSession().setAttribute("ErroMSG", Erro.erroMsg[Erro.SEM_PERMISSAO]);
//                return mapping.findForward("semPermissaoAlias");
//            }
            else {
                AccountantDAO cDAO = new AccountantDAO();
                
                ArrayList<Accountant> listContador = (ArrayList<Accountant>) cDAO.findAll();
                cDAO.closeDAO();
                request.getSession().setAttribute("ListContador", listContador);
                return mapping.findForward("relContadorAllAlias");
                
            }

        } catch (Exception e) {
            System.err.println("FINDALLCONTADOR.execute() " + e.getMessage());
            return mapping.findForward("erroAlias");
        }
     
    }
    
    
}
